﻿using equinoxWeb.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace equinoxWeb.Controllers
{
    public class EquinoxController : Controller
    {
        protected ActionResult defaultAction;
        protected int idClienteLogueado;
        protected bool esCliente = false;
        public string mensajeError = "";

        protected override void ExecuteCore()
        {
            ViewBag.enSesion = false;
            //inicio del bloque login
            bool esValido =CuentaController.validarLogueo(HttpContext);
            //fin del bloque login
            if (!esValido)
            {
                defaultAction = RedirectToAction("Ingresar", "Cuenta", new { returnUrl = HttpContext.Request.RawUrl });
                ViewBag.lang = CuentaController.getIdioma(this.HttpContext);
            }
            else
            {
                Usuario user = CuentaController.getUsuario(this.HttpContext);
                ViewBag.esCliente = !(user.IdCliente == 0);
                ViewBag.idClienteLogueado = user.IdCliente;
                ViewBag.enSesion = true;
                ViewBag.lang = CuentaController.getIdioma(this.HttpContext);
                idClienteLogueado = user.IdCliente;
                esCliente = !(user.IdCliente == 0); 
                ViewBag.nombreUsuario = CuentaController.getNombre(this.HttpContext);

            }

                base.ExecuteCore();
                //System.Console.WriteLine();
            
        }

    }
}
